refactor(cli): RunE migration, auth dedup, TTY-aware spinner, non-interactive guards - #158
Merged
Merged
Conversation
…eractive guards Command hygiene refactor for the hand-written CLI commands. Behavior (including exit codes and output streams) is preserved. - os.Exit -> RunE: convert bespoke command bodies (auth, fix, status, findings, ci, open, whoami, init, mcp, pentest, repos, update) to return errors instead of calling os.Exit mid-body, so deferred logger.Close runs and the commands are testable. Centralize error->exit-code mapping in main.go via a typed exitCodeError and ExitCodeForError; preserves ExitAuthError(2), ExitNetworkError(3), and ExitFindings(1). Set rootCmd.SilenceUsage=true / SilenceErrors=false so cobra prints each error once. - Auth boilerplate dedup: route fix/status/findings/ci through the existing resolveCommandAuth helper (now error-returning) instead of repeating resolveHost->GetNullifyToken->NewNullifyClient-> LoadCredentials. Added commandAuthContext.Client(). - TTY-aware spinner: NewSpinner stays silent when stderr is not a terminal, avoiding ANSI/braille noise in CI logs. - Non-interactive guards: auth login host prompt and the init wizard domain step now fail fast with a clear error when stdin is not a TTY instead of blocking on a read. The generated `api` commands and their getAPIClient factory are unchanged (resolveHost retains its os.Exit wrapper for that path). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Member
Author
|
Status check (2026-05-28): still relevant. Nothing on |
Member
Author
CODEX COUNCIL VERDICT: APPROVEDAdvisory AI review completed against merged head
Validation:
GitHub Actions restarted for the merged head. No failing checks are present at the time of this verdict; queued checks still need to complete. |
tim-thacker-nullify
marked this pull request as ready for review
July 29, 2026 02:33
dnjg
reviewed
Jul 31, 2026
dnjg
previously approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Command hygiene refactor of the hand-written CLI commands. Behavior — including exit codes and output streams — is preserved; this is a structural/testability pass only.
1.
os.Exit→RunEBespoke commands previously used
Run:withos.Exit(...)mid-body, which skipsdefer logger.Close(ctx)and is untestable. Convertedauth(login/logout/status/token/switch/config),fix,status,findings,ci(gate/report),open,whoami,init,mcp,pentest,repos, andupdatetoRunEreturning errors.Error → exit-code mapping is now centralized in one place:
cmd/cli/cmd/exitcodes.godefines a typedexitCodeErrorpluswithExitCode/authError/networkError/findingsErrorconstructors andExitCodeForError.cmd/cli/main.gocallsos.Exit(cmd.ExitCodeForError(err)).rootCmd.SilenceUsage = true(no usage dump on runtime errors) andSilenceErrors = false(cobra prints the error once).Exit codes are unchanged:
ExitAuthError(2),ExitNetworkError(3),ExitFindings(1), malformed-host (1). Theci gatecommand keeps its stdout gate-failure summary and silences cobra's stderr echo so its output stays byte-identical.The generated
apicommands and theirgetAPIClientfactory are untouched —resolveHostkeeps anos.Exitwrapper delegating to the new error-returningresolveHostEfor that path.2. Auth boilerplate dedup
fix,status,findings, andcieach repeatedresolveHost → GetNullifyToken → NewNullifyClient → LoadCredentials → extract QueryParameters. They now route through the existingresolveCommandAuthhelper (made error-returning, with a newcommandAuthContext.Client()).3. TTY-aware spinner
internal/output/spinner.goNewSpinnernow stays silent when stderr is not a terminal, so it no longer pollutes CI logs with ANSI escape sequences and braille frames.4. Non-interactive guards
auth loginhost prompt and theinitwizard's domain step now fail fast with a clear error ("not a terminal; pass --host …") when stdin is not a TTY, instead of blocking forever on a read in CI/pipes.Testing
GOWORK=off CGO_ENABLED=0 go build ./...GOWORK=off go vet ./...GOWORK=off go test ./...(all green)golangci-lint runon changed packages (0 issues)exitcodes_test.gocovering the central exit-code mapping.🤖 Generated with Claude Code
Final base-integration follow-up
Merged current
maininc7856cc03adand resolved the command-hygiene conflicts while preserving the newer fail-closed CI gate, SARIF reporting, refreshing MCP API client, and dependency-analysis exit codes.The handwritten
scan,sbom, andthreatcommands added onmainnow follow the sameRunEand centralized error path. The generated-command compatibility wrapper remains intact. The API generator target now runs the full generator package, and generated Go output is normalized deterministically without trailing blank lines.Validation on the merged head:
GOWORK=off go test ./...GOWORK=off CGO_ENABLED=0 go build ./...GOWORK=off go vet ./...golangci-lint run ./...(0 issues)GOWORK=off make generate-api, followed by a second generation pass with no working-tree driftgit diff --check